//
//  SERegistrationDoctorDateView.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/6.
//

import UIKit

protocol SERegistrationDoctorDateViewDelegate: NSObjectProtocol {
    func registrationDoctorDateViewBtnAction(model: SERegistrationDoctorShift)
}

class SERegistrationDoctorDateView: UIView {

    @IBOutlet var view: UIView!
    @IBOutlet weak var dateLabel: UILabel!
    @IBOutlet weak var departmentLabel: UILabel!
    @IBOutlet weak var feeLabel: UILabel!
    @IBOutlet weak var confirmBtn: UIButton!
    @IBAction func confirmBtnAction(_ sender: UIButton) {
        delegate?.registrationDoctorDateViewBtnAction(model: model)
    }

    weak var delegate: SERegistrationDoctorDateViewDelegate?
    var model = SERegistrationDoctorShift()

    override init(frame: CGRect) {
        super.init(frame: frame)
        loadNib()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        loadNib()
    }

    func updateView(model: SERegistrationDoctorShift) {
        self.model = model
        dateLabel.text = model.shiftDate + model.registerPeriod
        departmentLabel.text = model.deptName
        feeLabel.isHidden = true
        confirmBtn.backgroundColor = model.registerNumber > 0 ? Asset.main.color : UIColor(hex: "#F3B446")
        confirmBtn.isEnabled = model.registerNumber > 0
    }

    func loadNib() {
        view = UINib.init(nibName: String(describing: type(of: self)), bundle: nil).instantiate(withOwner: self, options: nil).last as? UIView
        view.frame = bounds
        view.layer.cornerRadius = view.frame.size.height / 2.0
        view.layer.masksToBounds = true
        addSubview(view)
    }

}
